package cn.com.pansky.util;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.imageio.stream.FileImageOutputStream;

public class ByteToImageUtil {
	// byte数组到图片
	public void byte2image(byte[] data, String path) {
		if (data.length < 3 || path.equals(""))
			return;
		try {
			FileImageOutputStream imageOutput = new FileImageOutputStream(
					new File(path));
			imageOutput.write(data, 0, data.length);
			imageOutput.close();
			System.out.println("Make Picture success,Please find image in "
					+ path);
		} catch (Exception ex) {
			System.out.println("Exception: " + ex);
			ex.printStackTrace();
		}
	}
	
	public static String getSpecifiedDayBefore(String specifiedDay) {//可以用new Date().toLocalString()传递参数  
        String str1 = specifiedDay.substring(0, 4);
        String str2 = specifiedDay.substring(4, 6);
        String str3 = specifiedDay.substring(6, 8);
        specifiedDay = str1+"-"+str2+"-"+str3;
		Calendar c = Calendar.getInstance();  
        Date date = null;  
        try {  
            date = new SimpleDateFormat("yy-MM-dd").parse(specifiedDay);  
        } catch (ParseException e) {  
            e.printStackTrace();  
        }  
        c.setTime(date);  
        int day = c.get(Calendar.DATE);  
        c.set(Calendar.DATE, day - 1);  
  
        String dayBefore = new SimpleDateFormat("yyyy-MM-dd").format(c  
                .getTime());  
        dayBefore = dayBefore.replaceAll("-", "");
        return dayBefore;  
    }  
	
	public static void main(String[] args) {
		System.out.println(getSpecifiedDayBefore("20160301"));
	}

}
